﻿using System.Threading.Tasks;
using battlenet.wow.rt.domain.objects;
using battlenet.wow.rt.sdk.Data.Proxy;

namespace battlenet.wow.rt.sdk
{
    public class WowCharacterService
    {
        private static readonly CharacterProfileProxy Proxy = new CharacterProfileProxy();

        /// <summary>
        /// Gets the character profile asynchronously.
        /// </summary>
        /// <param name="realm">The realm.</param>
        /// <param name="characterName">Name of the character.</param>
        /// <param name="fields">The fields.</param>
        /// <returns></returns>
        public async static Task<WowCharacter> GetCharacterAsync(string realm, string characterName, params string[] fields)
        {
            return await Proxy.GetCharacterProfileAsync(realm, characterName, fields);
        }
    }

    public class WowAuctionHouseService
    {
        private static readonly AuctionHouseProxy Proxy = new AuctionHouseProxy();

        /// <summary>
        /// Gets the auction house files asynchronously.
        /// </summary>
        /// <param name="realm">The realm.</param>
        /// <returns></returns>
        public async static Task<AuctionHouseFileCollection> GetAuctionHouseFilesAsync(string realm)
        {
            return await Proxy.GetAuctionHouseFilesAsync(realm);
        }

        /// <summary>
        /// Gets the json contents of the first file returned from GetAuctionHouseFiles.
        /// </summary>
        /// <param name="realm"></param>
        /// <returns></returns>
        public async static Task<string> GetAuctionHouseItemsJsonAsync(string realm)
        {
            var files = await GetAuctionHouseFilesAsync(realm);
            var auctionHouseResults = await HttpRequestHelper.GetHttpResponse(files[0].Uri);
            return auctionHouseResults.Item2;
        }
    }

    public class WowItemService
    {
        private static readonly ItemDetailProxy Proxy = new ItemDetailProxy();

        /// <summary>
        /// Gets the item detail.
        /// </summary>
        /// <param name="itemId">The item identifier.</param>
        /// <returns></returns>
        public async static Task<ItemDetail> GetItemDetail(int itemId)
        {
            return await Proxy.GetItemDetail(itemId);
        }
    }
}
